package app;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.boot.web.servlet.context.ServletWebServerInitializedEvent;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.context.ApplicationListener;

/**
 * Spring Boot 应用的入口文件
 */
@SpringBootApplication
public class AppStart implements ApplicationListener<ServletWebServerInitializedEvent>, WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> {
    private static final Logger logger = LoggerFactory.getLogger(AppStart.class);

    public static void main(String[] args) {
        SpringApplication.run(AppStart.class, args);
        logger.info("app started!");
    }

    @Override
    public void customize(ConfigurableServletWebServerFactory factory) {

    }

    @Override
    public void onApplicationEvent(ServletWebServerInitializedEvent servletWebServerInitializedEvent) {
        System.out.println("server port : ["+servletWebServerInitializedEvent.getWebServer().getPort()+"]");
    }
}
